<template>
	<view>
		<view class="header">
			<view class="navbar">
				<view class="navbar-fixed">
					<!-- 状态栏小程序撑起高度 -->
					<view :style="{height:statusBarHeight+'px'}"></view>
					<view class="navbar-content" :style="{height:navBarHeight+'px',width:windowWidth+'px'}">
						<image src="../../static/jt6.png" @click="back()"></image>
						<view class="navbar-search">优生活商城</view>
					</view>
				</view>
				<!-- 需要添加占位符高度  状态栏高度+导航栏高度（否则下面tab会塌陷）indexOf-->
				<view :style="{height: statusBarHeight+navBarHeight+'px'}"></view>
			</view>
		</view>
		<view class="searchbox" @click="togoodslist()">
			<view class="search">
				<view class="scan">
					<image src="../../static/sao.png"></image>
				</view>
				<view class="inputbox">
					<input placeholder="搜索" />
				</view>
				<view class="searchbut">搜索</view>
			</view>
		</view>
		<view class="classify">
			<view class="catebox" v-for="(item,index) in 8" :key="index">
				<image src="../../static/more.png"></image>
				<view>时令生鲜</view>
			</view>
		</view>
		<goods :logo="true"></goods>
	</view>
</template>

<script>
	import goods from '../../components/goods.vue'
	export default {
		components:{
			goods
		},
		data() {
			return {
				statusBarHeight: 20,
				/* 状态栏高度 */
				navBarHeight: 45,
				/* 导航栏高度 */
				windowWidth: 375,
				/* 窗口宽度 */
				/* 设定状态栏默认高度 */
			}
		},
		onShow() {
			this.getnav()
		},
		methods: {
			getnav() {
				// 获取手机系统信息
				const info = uni.getSystemInfoSync()
				// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
				this.statusBarHeight = info.statusBarHeight
				this.windowWidth = info.windowWidth
				// 除了h5 app mp-alipay的情况下执行
				// #ifndef H5 || APP-PLUS || MP-ALIPAY
				// 获取胶囊的位置
				const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				console.log(menuButtonInfo);
				// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
				this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info
					.statusBarHeight)
				this.windowWidth = menuButtonInfo.left
				// #endif
			},
			togoodslist(){
				uni.navigateTo({
					url:'/pages/goodslist/goodslist'
				})
			},
			back(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.header{
		height: 168rpx;
		background: url(https://zdcloud.zxkjnc.com/images/6165.png) no-repeat;
		width: 100%;
		background-size: 100% 168rpx;
	}
	.navbar {
		.navbar-fixed {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 399;
			width: 100%;
			// height: 102rpx;
			// padding-bottom: 20rpx;
			background: transparent;
	
	
			.navbar-content {
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 0rpx 30rpx;
				// height: 142rpx;
				box-sizing: border-box;
	
				image {
					width: 44rpx;
					height: 44rpx;
					margin-right: 20rpx;
				}
	
				.navbar-search {
					display: flex;
					align-items: center;
					// padding: 0 10px;
					width: 100%;
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #F94D29;
	
				}
	
			}
		}
	}
	.searchbox {
		width: 100%;
		height: 134rpx;
		display: flex;
		align-items: center;
		// margin-top: 40rpx;
	
		.search {
			width: 690rpx;
			height: 40rpx;
			padding: 15rpx 0;
			background: #FFFFFF;
			border-radius: 36rpx;
			border: 2rpx solid #F94D29;
			display: flex;
			align-items: center;
			margin: 0 auto;
	
			.scan {
				width: 76rpx;
				text-align: center;
				border-right: solid 2rpx #F2F2F2;
	
				image {
					width: 26rpx;
					height: 26rpx;
				}
			}
	
			.inputbox {
				width: 448rpx;
				height: 40rpx;
				padding: 0 24rpx;
	
				>input {
					width: 100%;
				}
			}
	
			.searchbut {
				width: 112rpx;
				height: 62rpx;
				background: linear-gradient(180deg, #F94D29 0%, #F99529 100%);
				border-radius: 36rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #F7F7F7;
				line-height: 62rpx;
				text-align: center;
			}
		}
	}
	.classify{
		width: 690rpx;
		height: 416rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		display: flex;
		flex-wrap: wrap;
		margin: 0rpx auto 0 auto;
		font-size: 28rpx;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #222222;
		.catebox{
			width: 25%;
			text-align: center;
			height: 208rpx;
			image{
				width: 113rpx;
				height: 112rpx;
				margin: 20rpx 0;
			}
		}
	}
	.jp{
		width: 228rpx;
		height: 46rpx;
	}

</style>
